package com.edu.tool.controller.captcha;


import com.edu.tool.annotation.NotCheckToken;
import com.edu.tool.constant.MsgConstant;
import com.edu.tool.exception.captcha.CaptchaException;
import com.edu.tool.service.user.SysCaptchaService;
import com.edu.tool.util.MsgUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping(value = "/api/v1")
@RestController
@Api(value="验证码接口")
public class SysCaptchaController {
    @Autowired
    private SysCaptchaService captchaService;

    @RequestMapping(value = "/captcha", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "captcha", notes = "captcha")
    @NotCheckToken
    public Map getCaptcha(@RequestParam(required = false) Integer tenantId,
                          @RequestParam String clientIp)  {

        try {
            Map ret = captchaService.create(tenantId, clientIp);
            return MsgUtil.retMap("captcha",ret);
        }catch(CaptchaException cte){
            return MsgUtil.retMsgMap(MsgConstant.FAILED_TO_GETCAPTCHA);
        }


    }


}
